﻿@{
    ViewBag.Title = "DefaultAdd";
    Layout = null;
}


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>学生添加</title>

    <script src="~/libs/jquery/jquery.js"></script>
    <link href="//unpkg.com/layui@2.9.16/dist/css/layui.css" rel="stylesheet">
    <script src="//unpkg.com/layui@2.9.16/dist/layui.js"></script>

</head>
<body>
    <h1>学生添加</h1>
    <form class="layui-form layui-form-pane" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">学生姓名</label>
            <div class="layui-input-block">
                <input type="text" name="name" id="name" required autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" pane>
            <label class="layui-form-label">年龄</label>
            <div class="layui-input-block">
                <input type="text" name="passage" id="passage" required autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
            </div>
        </div>
        
        <div class="layui-form-item">
            <button class="layui-btn" type="button" lay-submit lay-filter="btnAdd">确认</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </form>

    <script>
        layui.use(['form', 'jquery', 'element'], function () {
            var form = layui.form,
                $ = layui.jquery;
            $ = layui.$;
            // 监听确认按钮点击事件
            form.on('submit(btnAdd)', function (data) {
                // 获取表单数据
                var data = {
                    name: $('#name').val(),
                    passage: $('#passage').val(),
                
                };
                console.log(data);
                // 发送 AJAX 请求
                $.ajax({
                 
                    url: "/Home/AddWangUser",
                    type: "GET",
                    contentType: 'application/json',   // 设置请求的类型
                    data:data,  // 将数据转换为JSON字符串
                    dataType: "json",
                    if(res) {
                        console.log(res);
                        layer.msg('添加权限成功', {
                            icon: 1,
                            time: 1000
                        }, function () {
                            location.herf = '/';
                        });
                    }
                    
                });
            });
        });
    </script>

</body>
</html>